<?php
$this->breadcrumbs=array(
	'Gallery'=>array('admin'),
	'Manage',
);

$this->menu=array(
    array()
);

    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/scripts/jquery.picasa.js');
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/scripts/jquery.tmpl.min.js');
?>
<style>
.album{
    height:100px;
}
.item{
    text-align:center;
    padding:10px;
    margin:10px;
}
</style>
<script id="albumTemplate" type="text/x-jquery-tmpl"> 
            <div class="well span2 item">
                <img src="{image}" class="album" alt="{title}" />
                <div>
                <p>{title}</p>
                <button class="actionbutton btn {class}" data-album="{id}">{buttontext}</button>
                </div>
            </div>
</script>

<div id="noalbum" class="alert alert-block alert-warning fade in">Nincs még galéria.</div>
<div id="gallery"></div>

<script>

function setGallery(album, cb){
    $.getJSON('<?php echo $this->createAbsoluteUrl('gallery/ajaxset');?>?album='+album, function(res){
        if(cb)cb(res);
    });
}

function truncate(obj){
    a = [];
    for(o in obj){
        a.push(obj[o].album);
    }
    return a;
}

var ALBUMS = truncate(<?php echo CJSON::encode($albums) ?>);

String.prototype.replaceAll = function(a, b){
  return this.replace(new RegExp(a, 'g'),b);
}
</script>
<?php
$picasaID = Yii::app()->params['picasa.user.id'];
$picasaLogo = Yii::app()->baseUrl.'/images/logo_picasa.gif';

Yii::app()->clientScript->registerScript('gallerymanage', <<<SCRIPTEM

$(function(){
    
    
    $('#adminmenu').html('<li><img src="$picasaLogo" onclick="window.open(\'https://picasaweb.google.com/home\', \'Picasa\',\'status=1,scrollbars=1\');" style="cursor:pointer;"/></li>');

    $("#albums").picasaAlbums('$picasaID', function(albums){
        
        $('#noalbum').remove();;
            
        tmpl = $('#albumTemplate').text();
        
        $(albums).each(function(i, album){
           a = tmpl.replaceAll('{image}',album.thumb).replaceAll('{title}',album.title).replaceAll('{id}', album.id);
        //console.log(ALBUMS);
           if($.inArray(album.id, ALBUMS) > -1){
                a = a.replace('{class}', 'btn-danger').replaceAll('{buttontext}', 'Elrejt');
           }else{
                a = a.replace('{class}', '').replaceAll('{buttontext}', 'Aktiválás');
           }
           
           $('#gallery').append(a); 
        });
    });

   
   $('button.actionbutton').live('click',function(){
        _id = $(this).attr('data-album');
        _this = this;
        
        $(_this).attr('disabled',true);
        setGallery(_id, function(res){
            if(res.status == 'active'){               
                $(_this).addClass('btn-danger').text('Elrejt');                
            } else {
                $(_this).removeClass('btn-danger').text('Aktiválás');
            }
            $(_this).attr('disabled',false);
        });
        
        
   });   
   
    
});



SCRIPTEM
, CClientScript::POS_READY);

?>